#include<bits/stdc++.h>
using namespace std;
int const maxn=20;
int a[maxn],c[maxn];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",a+i);
        int ans=0;
        for(int s=0;s<(1<<n);s++){
            for(int i=0;i<n;i++){
                if((s>>i)&1)c[i+1]=0;
                else c[i+1]=1;
            }
            int lstr,lstb,res=0;
            lstr=lstb=0;
            for(int i=1;i<=n;i++){
                if(c[i]==0&&a[i]==lstr)res+=a[i];
                if(c[i]==1&&a[i]==lstb)res+=a[i];
                if(c[i])lstb=a[i];
                else lstr=a[i];
            }
            ans=max(ans,res);
        }
        printf("%d\n",ans);
    }
}